package com.android.djlmapp.adapter.order;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.SparseArray;

import com.android.djlmapp.fragment.ChildOrderFragment;

import java.util.ArrayList;
import java.util.List;

import static com.android.djlmapp.fragment.ChildOrderFragment.ORDER_TYPE;

/**
 * @Author wangziheng
 * @ProjectName djlm
 * @ClassName OrderPagerAdapter
 * @package com.android.djlmapp.adapter
 * @data 2018/12/5 18:57
 * @Describe
 * @Change
 */
public class OrderPagerAdapter extends FragmentPagerAdapter {

    public static SparseArray<String> mOrderTypeSparseArray;
    static {
        /**
         * 订单类型ID和订单类型名称
         */
        mOrderTypeSparseArray = new SparseArray<>();
        mOrderTypeSparseArray.put(ChildOrderFragment.ALL_ORDER_TYPE,"全部");
        mOrderTypeSparseArray.put(ChildOrderFragment.KAIKA_ORDER_TYPE,"开卡");
        mOrderTypeSparseArray.put(ChildOrderFragment.TEL_CHARGE_ORDER_TYPE,"话费");
        mOrderTypeSparseArray.put(ChildOrderFragment.FLOW_CHARGE_ORDER_TYPE,"流量");
        mOrderTypeSparseArray.put(ChildOrderFragment.BROADBAND_ORDER_TYPE,"宽带");
        mOrderTypeSparseArray.put(ChildOrderFragment.TERMINAL_ORDER_TYPE,"手机");
        mOrderTypeSparseArray.put(ChildOrderFragment.Q_MONEY_CHARGE_ORDER_TYPE,"Q币充值");
        mOrderTypeSparseArray.put(ChildOrderFragment.GAME_CHARGE_ORDER_TYPE,"游戏充值");
    }
    private List<Fragment> mFragments;
    public OrderPagerAdapter(FragmentManager fm) {
        super(fm);
        mFragments = new ArrayList<>();
        for(int index = 0 ; index < ORDER_TYPE.length && index < mOrderTypeSparseArray.size(); index ++){
            ChildOrderFragment childOrderFragment = ChildOrderFragment.getInstance(mOrderTypeSparseArray.get(ORDER_TYPE[index]),ORDER_TYPE[index]);
            mFragments.add(childOrderFragment);
        }
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mOrderTypeSparseArray.get(ORDER_TYPE[position]);
    }
}
